package com.atmc.controller;

import com.atmc.bean.Matchs;

import com.atmc.service.MatchsService;
import com.atmc.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.core.userdetails.User;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import java.util.*;

@Controller
public class MyController {
    @Autowired
    MatchsService matchsService;
    @Autowired
    UserService userService;
    //映射首页
    @RequestMapping({"/","/index"})
    public String toIndex(Model model){
        List<Matchs> list = matchsService.getAll();
        model.addAttribute("msg",list);
        return "index";
    }

    @RequestMapping("/test")
    public String toAgainIndex(Model model){
        List<Matchs> list = matchsService.getAll();
        User user = (User) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
        System.err.println(user);
        model.addAttribute("msg",list);
        model.addAttribute("userDetail",user);
        return "index";
    }

    @RequestMapping("/test1")
    public String tets(){
        return "redirect:http://localhost:9001/into";
    }

    //权限开启后 只能登录后才能进行访问主要页面
    @RequestMapping("/toLogin")
    public String test1(){
        return "login";
    }
    //没有权限只能返回提示页面，让用户登录页面
    @RequestMapping("/unauth")
    public String unauth(){
        return "unauth";
    }
    //注销账户、返回登录页面
    @RequestMapping("/logout")
    public String logout(){
        return "index";
    }



}
